package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/4/9 09:37
 * @apiNote
 */

public class Test02529MaximumCount {

    public static int maximumCount(int[] nums) {
        int count0 = 0;
        int count1 = 0;
        for (int num : nums) {
            if (num < 0) {
                count0++;
            } else if (num > 0) {
                count1++;
            }
        }
        return Math.max(count0, count1);
    }

    public int maximumCount1(int[] nums) {
        int pos1 = lowerBound(nums,0);
        int pos2 = lowerBound(nums,1);
        return Math.max(pos1,nums.length-pos2);
    }

    public static int lowerBound(int[] nums, int target) {
        int l = 0, r= nums.length;
        while (l < r) {
            int mid = l + r >> 1;
            if (nums[mid] < target) {
                l = mid + 1;
            } else {
                r = mid;
            }
        }
        return l;
    }
}
